<html>
	<head>
		<script>
		
		function applyFilter(){
			alert("applyFilter");
		}
		
		</script>	
		<title>Insert title here</title>
	</head>
<body>

<table id="tbAdvertisingRegistryV2" style="display:none"></table>

<script type="text/javascript">


var thisPageWidth;

if (window.innerWidth) //if browser supports window.innerWidth
	thisPageWidth = window.innerWidth   // document.write(window.innerWidth+" by "+window.innerHeight)
else if (document.width)
	thisPageWidth = document.width 
else if (document.all) //else if browser supports document.all (IE 4+)
	thisPageWidth = document.body.clientWidth
else  	thisPageWidth = 800;

 
function parsedForm(json)
{
// var h = "";

// if (json.post.val1)
// 	h += "<b>Value 1</b>: " + json.post.val1 + "<br />";

// h += "<b>Value 2</b>: " + json.post.val2 + "<br />";
// h += "<b>Value 3</b>: " + json.post.val3 + "<br />";

// if (json.post.val4)
// 	h += "<b>Value 4</b>: " + json.post.val4 + "<br />";

// $('#fdata').empty().html(h);
// $('.formdata').slideDown();

return json;
}

function formatData(data) {  
	 var rows = Array();  
	 $.each(data.rows,function(i,row){  
	                //id can be mapped to any attribute of the return object in the list  
	  rows.push({id:row.id, cell:[row.id,
	                              row.externalId,
	                              row.inventarNr,
	                              row.supportNr,
	                              row.supportTypeId,
	                              row.supportTypeName,
	                              row.regionCod,
	                              row.regionName,
	                              row.localityCod,
	                              row.localityName,
	                              row.adress,
	                              row.locationDescription,
	                              row.status
	                              ]});  
	 });  
	   
	 return {  
	  total:data.total,  
	  page:data.page,  
	  rows:rows  
	 };       
	}  


$("#tbAdvertisingRegistryV2").flexigrid({
	url: 'json/entity/a',
	dataType: 'json',
	colModel : [
		{display: '#', 						name : 'id', 					width : 40, 	sortable : true, align: 'center', hide:true},
		{display: 'External Id', 			name : 'externalId', 			width : 180, 	sortable : true, align: 'left', hide: true},
		{display: 'Inv. #', 				name : 'inventarNr', 			width : 40, 	sortable : true, align: 'left'},
		{display: 'Support #', 				name : 'supportNr', 			width : 50, 	sortable : true, align: 'left'},
		{display: 'Support type #', 		name : 'supportTypeId', 		width : 80, 	sortable : true, align: 'right', hide: true},
		{display: 'Support type', 			name : 'supportTypeName', 		width : 80, 	sortable : true, align: 'right'},
		{display: 'Region #', 				name : 'regionCod', 			width : 80, 	sortable : true, align: 'right', hide: true},
		{display: 'Region', 				name : 'regionName', 			width : 90, 	sortable : true, align: 'right'},
		{display: 'Locality #', 			name : 'localityCod', 			width : 80, 	sortable : true, align: 'right', hide: true},
		{display: 'Locality', 				name : 'localityName', 			width : 110, 	sortable : true, align: 'right'},
		{display: 'Address', 				name : 'adress', 				width : 200, 	sortable : true, align: 'left'},
		{display: 'Placement Description', 	name : 'locationDescription', 	width : 200, 	sortable : true, align: 'left'},
		{display: 'Status', 				name : 'status', 				width : 30, 	sortable : true, align: 'center'},
		{display: 'Photo', 					name : 'photo', 				width : 80, 	sortable : true, align: 'right', hide: true}
		],
	searchitems : [
		{display: 'Support type', name : 'supportTypeName'},
		{display: 'Region',		  name : 'regionName', isdefault: true}
		],
	sortname: "inventarNr",
	sortorder: "asc",
	usepager: true,
	title: 'Advertising Places',
	useRp: true,
	rp: 10,
	showTableToggleBtn: true,
	width: thisPageWidth - 365,
	onSubmit: addFormData,
	preProcess: formatData,
	height: 400,
	singleSelect: true
});

//This function adds paramaters to the post of flexigrid. You can add a verification as well by return to false if you don't want flexigrid to submit			

function addFormData(){
	//passing a form object to serializeArray will get the valid data from all the objects, but, if the you pass a non-form object, you have to specify the input elements that the data will come from
	var dt = $('#sform').serializeArray();
	$("#tbAdvertisingRegistryV2").flexOptions({params: dt});
	return true;
}

	
$('#sform').submit(function (){
	$('#tbAdvertisingRegistry').flexOptions({newp: 1}).flexReload();
	return false;
});
</script>




</body>
</html>